<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>基础菜单 - Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.8.11/layui/css/layui.css">
    <link rel="stylesheet" href="../../../css/deviceInfo.css">
    <style>
        .layui-layer-loading .layui-layer-content {
            width: 100%;
        }

        .layui-form-selectup dl {
            top: auto;
            bottom: auto;
        }
        .layui-table-body::-webkit-scrollbar {
            height: 10px;
        }
    </style>
</head>

<body class="layui-bg-gray">
    <div class="layui-row ">
        <div class="layui-panel layui-col-md2" style=" margin: 16px;">
            <div class="left-menu">
                <ul class="layui-menu" id="deviceInfo-menu">
                </ul>
            </div>
        </div>
        <div class="layui-panel layui-col-md8 layui-form" style=" margin: 16px;" lay-filter="demo-form">
            <!-- 给容器追加 class="layui-form-pane"，即可显示为方框风格 -->
            <form id="right-form">
            </form>
            <form onsubmit="return false;" id="Serial_Slave">

            </form>
        </div>
    </div>
    <!-- <script src="../lib/layui-v2.8.11/layui/layui.js"></script> -->
    <script src="../js/api.js" charset="utf-8"></script>
    <script src="../js/ajaxRequest.js" charset="utf-8"></script>
    <script type="text/html" id="templet-demo-theads-tool">
        <div class="layui-clear-space">
          <!-- <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs"  lay-event="detailSave"> 保存</a> -->
          <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="delete">删除</a>
        </div>
    </script>
    <script type="text/html" id="treeh">
       <a lay-on="test-offset"data-id="{{d.ID}}">{{=d.CollectName}}</a>
    </script>
    <a id="treeShow"></a>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
          <button class="layui-btn layui-btn-sm layui-btn-primary layui-border-green" lay-event="add">新增</button>         
        </div>
    </script>
    <script>
        layui.use(['dropdown', 'layer', 'util', 'form', 'table', 'element', 'tree', 'jquery'], function () {
            var data;
            var responseDatas;
            var optionsSet;
            var dropdown = layui.dropdown;
            var layer = layui.layer;
            var util = layui.util;
            var form = layui.form;
            var table = layui.table;
            var element = layui.element;
            var $ = layui.jquery;

            var tree = layui.tree;
            form1()
            GetSelectSerialInfo().then(function (responseData) {
                responseDatas = responseData
            })
            function form1() {
                $('#deviceInfo-menu').empty();




                //  sendAjaxRequest('GET', '/Serial/GetSerialInfo', null, function (response) {
                var loadingIndex = layer.load(3, {
                    content: '加载中...', // 自定义加载文本
                    shade: [0.4, '#fff'], // 遮罩透明度
                    time: 5 * 1000,
                });
                GetDeviceInfo().then(function (responseData) {
                    layer.close(loadingIndex);
                    data = responseData;
                    //  data = response.data;
                    // 遍历数据，动态生成菜单项
                    var html = '';
                    html += `
                    <li class="layui-menu-item-divider"></li><li class="layui-menu-item-group layui-menu-item-down">
                        <li lay-options="{id:0,ApplicationLayerProtocol:'1',DeviceInfoID:'',Name:'',Describe:'',IP:'',PORT:'',OHRT:'60',SPITV:'15',OHRTCode:'',
                            ComName:'',BAD:'9600',DAB:'8',CHC:'0',STO:'1',MQTTHostName:'ssl://iot.gdwater.gov.cn',MQTTPort:'8883',MQTTClientID:'',MQTTUsername:'',
                            MQTTAccessKey:'',MQTTSubscribe:'',MQTTPublish:'',ModbusTCPIP:'',ModbusTCPPORT:''}">
                            <div class="layui-menu-body-title" style="color: #16B777">新建上报平台信息</div>
                        </li>
                    </li>`
                    data.forEach(function (item) {
                        html += ` <li class="layui-menu-item-divider"></li><li class="layui-menu-item-group layui-menu-item-down" lay-options="{type: 'group'}">
      <div class="layui-menu-body-title">  ${item.Name}<i class="layui-icon layui-icon-up"></i> </div>`
                        html += '<ul>'
                        html += `
                        <li lay-options="{id: ${item.ID},DeviceInfoID:'${item.DeviceInfoID}',Name:'${item.Name}',Describe:'${item.Describe}',TransportLayerProtocol:'${item.TransportLayerProtocol}',
                        IsReportedData:'${item.IsReportedData}',ApplicationLayerProtocol:'${item.ApplicationLayerProtocol}',IP:'${item.IP}',PORT:'${item.PORT}',OHRT:'${item.OHRT}',SPITV:'${item.SPITV}',OHRTCode:'${item.OHRTCode}',
                            ComName:'${item.ComName}',BAD:'${item.BAD}',DAB:'${item.DAB}',CHC:'${item.CHC}',STO:'${item.STO}',MQTTHostName:'${item.MQTTHostName}',
                            MQTTPort:'${item.MQTTPort}',MQTTClientID:'${item.MQTTClientID}',MQTTUsername:'${item.MQTTUsername}',MQTTSubscribe:'${item.MQTTSubscribe}',
                            MQTTPublish:'${item.MQTTPublish}',MQTTAccessKey:'${item.MQTTAccessKey}',ModbusTCPIP:'${item.ModbusTCPIP}',ModbusTCPPORT:'${item.ModbusTCPPORT}'}">
                            <div class="layui-menu-body-title">属性</div>
                        </li>`
                        if (item.ApplicationLayerProtocol == 6) {
                            html += `<li lay-options="{ID:0,Name:'',Describe:'',Dev:'',Device_ID: ${item.ID},ApplicationLayerProtocol:'${item.ApplicationLayerProtocol}' }">
                                                    <div class="layui-menu-body-title" style="color: #16B777">新建集中器</div>
                                                </li>`
                            item.DeviceInfo_Concentrator.forEach(item1 => {
                                //集中器 第一层
                                html += `
                                <li class="layui-menu-item-group" >
                                  
                                        <li lay-options="{ID: ${item1.ID},Level:1,Name:'${item1.Name}',Describe:'${item1.Describe}',Dev:'${item1.Dev}' }">
                                            <div class="layui-menu-body-title" >${item1.Name}
                                            </li>
                                    `

                                //最里层 第二层
                                item1.DeviceInfo_Concentrator_User.forEach(item2 => {
                                    html += `
                                                    <li class="layui-menu-item-group" >
                                                        <ul>
                                                            <li lay-options="{id:${item.ID},DeviceInfo_Concentrator_ID:${item1.ID},DeviceInfo_Concentrator_User_ID:${item2.ID},ID: ${item2.ID} ,ApplicationLayerProtocol:'${item.ApplicationLayerProtocol}',Level:2,Name:'${item2.Name}',Describe:'${item2.Describe}',Mn:'${item2.Mn}' }">
                                                                <div class="layui-menu-body-title">${item2.Name}                                   
                                                                </div>                                                                    
                                                            </li>
                                                        </ul>
                                                    </li>`
                                })
                                html += `
                                            </div> 
                                            <div style="padding: 5px 15px;">
                                                <ul>
                                                    <li lay-options="{ID: 0,Name:'',Describe:'',Mn:'',Device_ID: ${item.ID},DeviceInfo_Concentrator_ID: ${item1.ID}
                                                    ,ApplicationLayerProtocol:'${item.ApplicationLayerProtocol}' }">
                                                        <div class="layui-menu-body-title" style="color: #16B777">新建用户表</div>
                                                    </li>  
                                                </ul>
                                            </div>                             
                                       
                                    
                                </li>`
                            })

                        }
                        if (item.ApplicationLayerProtocol != 2 && item.ApplicationLayerProtocol != 6) {
                            html += `<li lay-options="{id: ${item.ID},ApplicationLayerProtocol:'${item.ApplicationLayerProtocol}'}"><div class="layui-menu-body-title">配置</div></li>`
                        }
                        html += '</ul>'
                        html += '</li>'
                    });

                    $('#deviceInfo-menu').append(html);


                    // 初始化菜单
                    //  dropdown.init();

                    // 点击属性
                    dropdown.on('click(deviceInfo-menu)', function (options) {
                        optionsSet = options

                        // if(options.Describe==""||options.Describe==null)
                        var htmlR = '';
                        // 清空右侧表单内容
                        $('#right-form').empty();
                        $('#Serial_Slave').empty();
                        if (options.title == '属性' || options.title == '新建上报平台信息') {
                            htmlR += `
                            <div class="layui-card-header"><h3>属性</h3>
                                <span> 
                                   `
                            if (options.title != '新建上报平台信息') {
                                htmlR += ` <button class="layui-btn  layui-btn-primary layui-border-red" lay-submit  lay-filter="deviceInfodelete">
                                        <i class="layui-icon layui-icon-delete"> </i>  删除
                                    </button> `
                            }
                            htmlR += `<button class="layui-btn layui-btn-primary layui-border-green" lay-submit  lay-filter="submit">提交</button>
                                </span>
                            </div>
                            <div class="layui-card-body">
                                <li class="layui-menu  layui-menu-item-divider"></li>
                                <div class="layui-form-item topinput">
                                    <label class="layui-form-label required title">名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="Name" autocomplete="off" placeholder="请输入" lay-verify="required"
                                            value='${options.Name}' class="layui-input inputtitle">
                                    </div>
                                </div>
                                <div class="layui-form-item topinput">
                                    <label class="layui-form-label">描述</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="Describe" autocomplete="off" placeholder="请输入" 
                                            value='${options.Describe}' class="layui-input inputtitle">
                                        <input name="ID" style="display:none">
                                    </div>
                                </div>                               
                            </div><hr>`
                            htmlR += `     
                            <div class="layui-col-md6">
                                <div class="layui-card-body">
                                    <h4>传输层协议</h4>
                                    <hr>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label required">协议</label>
                                        <div id="TransportLayerProtocol">
                                            <select name="TransportLayerProtocol">
                                                <option value="1">TCP</option>                                             
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item topinput">
                                        <label class="layui-form-label required">远程主机地址</label>
                                        <div  class="input">
                                            <input type="text" name="IP" id="IP" autocomplete="off" placeholder="请输入"  ${options.ApplicationLayerProtocol === '1'
                                    || options.ApplicationLayerProtocol === '2' || options.ApplicationLayerProtocol === '6' ? 'lay-verify="required"' : ''} 
                                                value='${options.IP}' class="layui-input input2">
                                            <div class="layui-input-split iconCenter" title="点击测试TCP连接" lay-on="tcpsearch"><i id="icon"  class="layui-icon layui-icon-search"></i></div>
                                        </div> 
                                    </div>
                                    <div class="layui-form-item topinput">
                                        <label class="layui-form-label required">远程主机端口</label>
                                        <div  class="input">
                                            <input type="number" name="PORT" id="PORT" autocomplete="off" placeholder="请输入" ${options.ApplicationLayerProtocol === '1'
                                    || options.ApplicationLayerProtocol === '2' || options.ApplicationLayerProtocol === '6' ? 'lay-verify="required"' : ''} lay-affix="number"
                                                value='${options.PORT}' class="layui-input input2">
                                        </div>
                                    </div>
                                    <div class="layui-form-item topinput">
                                        <label class="layui-form-label required">设备ID</label>
                                        <div  class="input">
                                            <input type="text" name="DeviceInfoID" id="DeviceInfoID" autocomplete="off" placeholder="请输入" ${options.ApplicationLayerProtocol === '1'
                                    || options.ApplicationLayerProtocol === '2' ? 'lay-verify="required"' : ''} 
                                                value='${options.DeviceInfoID}' class="layui-input input2">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label required">是否上报</label>
                                        <div id="IsReportedData">
                                            <select name="IsReportedData">
                                                <option value="1"   ${options.IsReportedData === '1' ? 'selected' : ''}>上报</option>
                                                <option value="2"   ${options.IsReportedData === '2' ? 'selected' : ''}>不上报</option>                                                         
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <div class="layui-card-body">
                                    <h4>应用层协议</h4>
                                    <hr>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label required">协议</label>
                                        <div>
                                            <select name="ApplicationLayerProtocol" lay-filter="applicationLayerProtocol-filter" >
                                                <option value="1"   ${options.ApplicationLayerProtocol === '1' ? 'selected' : ''}>SLYUN</option>
                                                <option value="2"   ${options.ApplicationLayerProtocol === '2' ? 'selected' : ''}>DTU透传</option>
                                                <option value="3"   ${options.ApplicationLayerProtocol === '3' ? 'selected' : ''}>mqtts_广东水利物联网平台</option>
                                                <option value="4"   ${options.ApplicationLayerProtocol === '4' ? 'selected' : ''}>mqtts_OneNet</option>
                                                <option value="5"   ${options.ApplicationLayerProtocol === '5' ? 'selected' : ''}>ModbusTCPServer</option>
                                                <option value="6"   ${options.ApplicationLayerProtocol === '6' ? 'selected' : ''}>四联四表</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol !== '5' ? 'topinput' : 'hideinput'}" id="OHRT" >
                                        <label class="layui-form-label required">心跳周期(秒)</label>
                                        <div class="input">
                                            <input type="number" name="OHRT" autocomplete="off" placeholder="请输入" lay-verify="required" lay-affix="number"
                                                value='${options.OHRT}' class="layui-input ">
                                        </div>
                                    </div>
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '1' || options.ApplicationLayerProtocol === '3'
                                    || options.ApplicationLayerProtocol === '4' || options.ApplicationLayerProtocol === '6' ? 'topinput' : 'hideinput'}" id="SPITV" >
                                        <label class="layui-form-label required">数据传输周期(分)</label>
                                        <div class="input">
                                            <input type="number" name="SPITV" autocomplete="off" placeholder="请输入" lay-verify="required" lay-affix="number"
                                                value='${options.SPITV}' class="layui-input ">
                                        </div>
                                    </div>
                                      <div class="layui-form-item ${options.ApplicationLayerProtocol === '5' ? 'topinput' : 'hideinput'}" id="SPITV2" >
                                        <label class="layui-form-label required">数据更新周期(秒)</label>
                                        <div class="input">
                                            <input type="number" name="SPITV2" autocomplete="off" placeholder="请输入" lay-verify="required" lay-affix="number"
                                                value='${options.SPITV}' class="layui-input ">
                                        </div>
                                    </div>
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '2' ? 'topinput' : 'hideinput'}" id="OHRTCode">
                                        <label class="layui-form-label required">自定义心跳包</label>
                                        <div class="input">
                                            <input type="text" name="OHRTCode" autocomplete="off" placeholder="请输入" lay-verify="autoSpace" id="autoSpaceInput"
                                                value='${options.OHRTCode}' class="layui-input ">
                                        </div>
                                       
                                    </div>
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '2' ? 'topinput' : 'hideinput'}" id="ComName">
                                        <label class="layui-form-label required">串口名称</label>
                                        <div class="input">
                                            <input type="text" name="ComName" autocomplete="off" placeholder="请输入"
                                                value='${options.ComName}' class="layui-input ">
                                        </div>
                                    </div>
                                    <div class="${options.ApplicationLayerProtocol === '2' ? 'layui-form-item' : 'hideinput'} " id="BAD">
                                        <label class="layui-form-label required">波特率</label>
                                        <div>
                                            <select name="BAD">
                                                <option value="300"     ${options.BAD === '300' ? 'selected' : ''}>300</option>
                                                <option value="600"     ${options.BAD === '600' ? 'selected' : ''}>600</option>
                                                <option value="1200"    ${options.BAD === '1200' ? 'selected' : ''}>1200</option>
                                                <option value="2400"    ${options.BAD === '2400' ? 'selected' : ''}>2400</option>
                                                <option value="4800"    ${options.BAD === '4800' ? 'selected' : ''}>4800</option>
                                                <option value="9600"    ${options.BAD === '9600' ? 'selected' : ''}>9600</option>
                                                <option value="19200"   ${options.BAD === '19200' ? 'selected' : ''}>19200</option>
                                                <option value="38400"   ${options.BAD === '38400' ? 'selected' : ''}>38400</option>
                                                <option value="57600"   ${options.BAD === '57600' ? 'selected' : ''}>57600</option>
                                                <option value="115200"  ${options.BAD === '115200' ? 'selected' : ''}>115200</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="${options.ApplicationLayerProtocol === '2' ? 'layui-form-item' : 'hideinput'} "id="DAB">
                                        <label class="layui-form-label required">数据位</label>
                                        <div>
                                            <select name="DAB" >
                                                <option value="8"   ${options.DAB === '8' ? 'selected' : ''}>8位</option>
                                                <option value="7"   ${options.DAB === '7' ? 'selected' : ''}>7位</option>
                                                <option value="6"   ${options.DAB === '6' ? 'selected' : ''}>6位</option>
                                                <option value="5"   ${options.DAB === '5' ? 'selected' : ''}>5位</option>
                                                <option value="4"   ${options.DAB === '4' ? 'selected' : ''}>4位</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="${options.ApplicationLayerProtocol === '2' ? 'layui-form-item' : 'hideinput'} "id="CHC">
                                        <label class="layui-form-label required">校验方式</label>
                                        <div>
                                            <select name="CHC" >
                                                <option value="0"    ${options.CHC === '0' ? 'selected' : ''}>无校验</option>
                                                <option value="1"    ${options.CHC === '1' ? 'selected' : ''}>奇校验</option>
                                                <option value="2"    ${options.CHC === '2' ? 'selected' : ''}>偶校验</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="${options.ApplicationLayerProtocol === '2' ? 'layui-form-item' : 'hideinput'} "id="STO">
                                        <label class="layui-form-label required">停止位</label>
                                        <div>
                                            <select name="STO">
                                                <option value="1"   ${options.STO === '1' ? 'selected' : ''}>1</option>
                                                <option value="2"   ${options.STO === '2' ? 'selected' : ''}>2</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '5' ? 'topinput' : 'hideinput'}" id="ModbusTCPIP">
                                        <label class="layui-form-label required">Modbus_IP</label>
                                        <div class="input">
                                            <input type="text" name="ModbusTCPIP" autocomplete="off" placeholder="请输入" lay-verify="autoSpace" 
                                                value='${options.ModbusTCPIP}' class="layui-input ">
                                        </div>
                                       
                                    </div>
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '5' ? 'topinput' : 'hideinput'}" id="ModbusTCPPORT">
                                        <label class="layui-form-label required">Modbus_PORT</label>
                                        <div class="input">
                                            <input type="text" name="ModbusTCPPORT" autocomplete="off" placeholder="请输入" lay-verify="autoSpace" 
                                                value='${options.ModbusTCPPORT}' class="layui-input ">
                                        </div>
                                       
                                    </div>
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '3' || options.ApplicationLayerProtocol === '4' ? 'topinput' : 'hideinput'}" id="MQTTHostName">
                                        <label class="layui-form-label required">HostName</label>
                                        <div class="input">
                                            <input type="text" name="MQTTHostName" autocomplete="off" placeholder="请输入" lay-verify="autoSpace" 
                                                value='${options.MQTTHostName}' class="layui-input ">
                                        </div>
                                       
                                    </div>
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '3' || options.ApplicationLayerProtocol === '4' ? 'topinput' : 'hideinput'}" id="MQTTPort">
                                        <label class="layui-form-label required">Port</label>
                                        <div class="input">                                          
                                            <input type="number" name="MQTTPort" autocomplete="off" placeholder="请输入" lay-affix="number"
                                                value='${options.MQTTPort}' class="layui-input ">
                                        </div>
                                       
                                    </div>
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '3' || options.ApplicationLayerProtocol === '4' ? 'topinput' : 'hideinput'}" id="MQTTClientID">
                                        <label class="layui-form-label required">ClientID</label>
                                        <div class="input">
                                            <input type="text" name="MQTTClientID" autocomplete="off" placeholder="请输入"
                                                value='${options.MQTTClientID}' class="layui-input ">
                                        </div>
                                       
                                    </div>
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '3' || options.ApplicationLayerProtocol === '4' ? 'topinput' : 'hideinput'}" id="MQTTUsername">
                                        <label class="layui-form-label required">Username</label>
                                        <div class="input">
                                            <input type="text" name="MQTTUsername" autocomplete="off" placeholder="请输入" 
                                                value='${options.MQTTUsername}' class="layui-input ">
                                        </div>
                                       
                                    </div>   
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '3' || options.ApplicationLayerProtocol === '4' ? 'topinput' : 'hideinput'}" id="MQTTSubscribe">
                                        <label class="layui-form-label required">Subscribe</label>
                                        <div class="input">
                                            <input type="text" name="MQTTSubscribe" autocomplete="off" placeholder="请输入" 
                                                value='${options.MQTTSubscribe}' class="layui-input ">
                                        </div>
                                       
                                    </div>   
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '3' || options.ApplicationLayerProtocol === '4' ? 'topinput' : 'hideinput'}" id="MQTTPublish">
                                        <label class="layui-form-label required">Publish</label>
                                        <div class="input">
                                            <input type="text" name="MQTTPublish" autocomplete="off" placeholder="请输入" 
                                                value='${options.MQTTPublish}' class="layui-input ">
                                        </div>
                                       
                                    </div>   
                                    <div class="layui-form-item ${options.ApplicationLayerProtocol === '3' || options.ApplicationLayerProtocol === '4' ? 'topinput' : 'hideinput'}" id="MQTTAccessKey">
                                        <label class="layui-form-label required">AccessKey</label>
                                        <div class="input">
                                            <input type="text" name="MQTTAccessKey" autocomplete="off" placeholder="请输入" lay-verify="autoSpace" 
                                                value='${options.MQTTAccessKey}' class="layui-input ">
                                        </div>
                                       
                                    </div>                                  
                                    
                                </div>
                            </div>`
                            $('#right-form').append(htmlR);
                            form.render(); // 渲染全部表单
                            // 初始化时给 select 赋值
                            form.val('demo-form', {
                                'ID': options.id
                            });
                            // select 事件
                            form.on('select(applicationLayerProtocol-filter)', function (data) {
                                var value = data.value; // 获得被选中的值
                                if ($("#OHRT").hasClass("hideinput")) {
                                    $("#OHRT").toggleClass("hideinput").toggleClass("topinput");
                                }
                                if (value === "2") {
                                    //dtu透传
                                    ChangeSelectDisabled(false)
                                    if ($("#SPITV").hasClass("topinput")) {
                                        $("#SPITV").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#SPITV2").hasClass("topinput")) {
                                        $("#SPITV2").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#OHRTCode").hasClass("hideinput")) {
                                        $("#OHRTCode").toggleClass("hideinput").toggleClass("topinput");
                                    }
                                    if ($("#ComName").hasClass("hideinput")) {
                                        $("#ComName").toggleClass("hideinput").toggleClass("topinput");
                                    }
                                    if ($("#BAD").hasClass("hideinput")) {
                                        $("#BAD").toggleClass("hideinput").toggleClass("layui-form-item");
                                    }
                                    if ($("#DAB").hasClass("hideinput")) {
                                        $("#DAB").toggleClass("hideinput").toggleClass("layui-form-item");
                                    }
                                    if ($("#CHC").hasClass("hideinput")) {
                                        $("#CHC").toggleClass("hideinput").toggleClass("layui-form-item");
                                    }
                                    if ($("#STO").hasClass("hideinput")) {
                                        $("#STO").toggleClass("hideinput").toggleClass("layui-form-item");
                                    }

                                    //mqtt的参数
                                    if ($("#MQTTHostName").hasClass("topinput")) {
                                        $("#MQTTHostName").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTPort").hasClass("topinput")) {
                                        $("#MQTTPort").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTClientID").hasClass("topinput")) {
                                        $("#MQTTClientID").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTUsername").hasClass("topinput")) {
                                        $("#MQTTUsername").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTSubscribe").hasClass("topinput")) {
                                        $("#MQTTSubscribe").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTPublish").hasClass("topinput")) {
                                        $("#MQTTPublish").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTAccessKey").hasClass("topinput")) {
                                        $("#MQTTAccessKey").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    //modbus
                                    if ($("#ModbusTCPIP").hasClass("topinput")) {
                                        $("#ModbusTCPIP").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#ModbusTCPPORT").hasClass("topinput")) {
                                        $("#ModbusTCPPORT").toggleClass("topinput").toggleClass("hideinput");
                                    }

                                    if ($("#IP").attr("lay-verify") === undefined) {
                                        $("#IP").attr("lay-verify", "required");
                                    }
                                    if ($("#PORT").attr("lay-verify") === undefined) {
                                        $("#PORT").attr("lay-verify", "required");
                                    }
                                    if ($("#DeviceInfoID").attr("lay-verify") === undefined) {
                                        $("#DeviceInfoID").attr("lay-verify", "required");
                                    }

                                }
                                else if (value === "1") {
                                    //silianyun
                                    ChangeSelectDisabled(false)
                                    if ($("#SPITV").hasClass("hideinput")) {
                                        $("#SPITV").toggleClass("hideinput").toggleClass("topinput");
                                    }
                                    if ($("#SPITV2").hasClass("topinput")) {
                                        $("#SPITV2").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#OHRTCode").hasClass("topinput")) {
                                        $("#OHRTCode").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#ComName").hasClass("topinput")) {
                                        $("#ComName").toggleClass("topinput").toggleClass("hideinput");
                                    }

                                    if ($("#BAD").hasClass("layui-form-item")) {
                                        $("#BAD").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    if ($("#DAB").hasClass("layui-form-item")) {
                                        $("#DAB").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    if ($("#CHC").hasClass("layui-form-item")) {
                                        $("#CHC").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    if ($("#STO").hasClass("layui-form-item")) {
                                        $("#STO").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    //mqtt的参数
                                    if ($("#MQTTHostName").hasClass("topinput")) {
                                        $("#MQTTHostName").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTPort").hasClass("topinput")) {
                                        $("#MQTTPort").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTClientID").hasClass("topinput")) {
                                        $("#MQTTClientID").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTUsername").hasClass("topinput")) {
                                        $("#MQTTUsername").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTSubscribe").hasClass("topinput")) {
                                        $("#MQTTSubscribe").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTPublish").hasClass("topinput")) {
                                        $("#MQTTPublish").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTAccessKey").hasClass("topinput")) {
                                        $("#MQTTAccessKey").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    //modbus
                                    if ($("#ModbusTCPIP").hasClass("topinput")) {
                                        $("#ModbusTCPIP").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#ModbusTCPPORT").hasClass("topinput")) {
                                        $("#ModbusTCPPORT").toggleClass("topinput").toggleClass("hideinput");
                                    }

                                    if ($("#IP").attr("lay-verify") === undefined) {
                                        $("#IP").attr("lay-verify", "required");
                                    }
                                    if ($("#PORT").attr("lay-verify") === undefined) {
                                        $("#PORT").attr("lay-verify", "required");
                                    }
                                    if ($("#DeviceInfoID").attr("lay-verify") === undefined) {
                                        $("#DeviceInfoID").attr("lay-verify", "required");
                                    }


                                }
                                else if (value === "3" || value === "4" || value === "5") {//mqtts or modbustcp
                                    ChangeSelectDisabled(true)
                                    if ($("#SPITV").hasClass("hideinput")) {
                                        $("#SPITV").toggleClass("hideinput").toggleClass("topinput");
                                    }
                                    if ($("#SPITV2").hasClass("topinput")) {
                                        $("#SPITV2").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#OHRTCode").hasClass("topinput")) {
                                        $("#OHRTCode").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#ComName").hasClass("topinput")) {
                                        $("#ComName").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#BAD").hasClass("layui-form-item")) {
                                        $("#BAD").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    if ($("#DAB").hasClass("layui-form-item")) {
                                        $("#DAB").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    if ($("#CHC").hasClass("layui-form-item")) {
                                        $("#CHC").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    if ($("#STO").hasClass("layui-form-item")) {
                                        $("#STO").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    if (value === "3" || value === "4") { //mqtt
                                        if ($("#MQTTHostName").hasClass("hideinput")) {
                                            $("#MQTTHostName").toggleClass("hideinput").toggleClass("topinput");
                                        }
                                        if ($("#MQTTPort").hasClass("hideinput")) {
                                            $("#MQTTPort").toggleClass("hideinput").toggleClass("topinput");
                                        }
                                        if ($("#MQTTClientID").hasClass("hideinput")) {
                                            $("#MQTTClientID").toggleClass("hideinput").toggleClass("topinput");
                                        }
                                        if ($("#MQTTUsername").hasClass("hideinput")) {
                                            $("#MQTTUsername").toggleClass("hideinput").toggleClass("topinput");
                                        }
                                        if ($("#MQTTSubscribe").hasClass("hideinput")) {
                                            $("#MQTTSubscribe").toggleClass("hideinput").toggleClass("topinput");
                                        }
                                        if ($("#MQTTPublish").hasClass("hideinput")) {
                                            $("#MQTTPublish").toggleClass("hideinput").toggleClass("topinput");
                                        }
                                        if ($("#MQTTAccessKey").hasClass("hideinput")) {
                                            $("#MQTTAccessKey").toggleClass("hideinput").toggleClass("topinput");
                                        }

                                        if ($("#ModbusTCPIP").hasClass("topinput")) {
                                            $("#ModbusTCPIP").toggleClass("topinput").toggleClass("hideinput");
                                        }
                                        if ($("#ModbusTCPPORT").hasClass("topinput")) {
                                            $("#ModbusTCPPORT").toggleClass("topinput").toggleClass("hideinput");
                                        }
                                    } else if (value === "5") {//modbus
                                        if ($("#OHRT").hasClass("topinput")) {
                                            $("#OHRT").toggleClass("topinput").toggleClass("hideinput");
                                        }
                                        if ($("#SPITV").hasClass("topinput")) {
                                            $("#SPITV").toggleClass("topinput").toggleClass("hideinput");
                                        }
                                        if ($("#SPITV2").hasClass("hideinput")) {
                                            $("#SPITV2").toggleClass("hideinput").toggleClass("topinput");
                                        }
                                        if ($("#MQTTHostName").hasClass("topinput")) {
                                            $("#MQTTHostName").toggleClass("topinput").toggleClass("hideinput");
                                        }
                                        if ($("#MQTTPort").hasClass("topinput")) {
                                            $("#MQTTPort").toggleClass("topinput").toggleClass("hideinput");
                                        }
                                        if ($("#MQTTClientID").hasClass("topinput")) {
                                            $("#MQTTClientID").toggleClass("topinput").toggleClass("hideinput");
                                        }
                                        if ($("#MQTTUsername").hasClass("topinput")) {
                                            $("#MQTTUsername").toggleClass("topinput").toggleClass("hideinput");
                                        }
                                        if ($("#MQTTSubscribe").hasClass("topinput")) {
                                            $("#MQTTSubscribe").toggleClass("topinput").toggleClass("hideinput");
                                        }
                                        if ($("#MQTTPublish").hasClass("topinput")) {
                                            $("#MQTTPublish").toggleClass("topinput").toggleClass("hideinput");
                                        }
                                        if ($("#MQTTAccessKey").hasClass("topinput")) {
                                            $("#MQTTAccessKey").toggleClass("topinput").toggleClass("hideinput");
                                        }

                                        //modbus
                                        if ($("#ModbusTCPIP").hasClass("hideinput")) {
                                            $("#ModbusTCPIP").toggleClass("hideinput").toggleClass("topinput");
                                        }
                                        if ($("#ModbusTCPPORT").hasClass("hideinput")) {
                                            $("#ModbusTCPPORT").toggleClass("hideinput").toggleClass("topinput");
                                        }

                                    }
                                    if ($("#IP").attr("lay-verify") !== undefined) {
                                        $("#IP").removeAttr('lay-verify');
                                    }
                                    if ($("#PORT").attr("lay-verify") !== undefined) {
                                        $("#PORT").removeAttr('lay-verify');
                                    }
                                    if ($("#DeviceInfoID").attr("lay-verify") !== undefined) {
                                        $("#DeviceInfoID").removeAttr('lay-verify');
                                    }
                                }
                                else if (value === "6") {
                                    //si
                                    ChangeSelectDisabled(false)
                                    if ($("#SPITV").hasClass("hideinput")) {
                                        $("#SPITV").toggleClass("hideinput").toggleClass("topinput");
                                    }
                                    if ($("#SPITV2").hasClass("topinput")) {
                                        $("#SPITV2").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#OHRTCode").hasClass("topinput")) {
                                        $("#OHRTCode").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#ComName").hasClass("topinput")) {
                                        $("#ComName").toggleClass("topinput").toggleClass("hideinput");
                                    }

                                    if ($("#BAD").hasClass("layui-form-item")) {
                                        $("#BAD").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    if ($("#DAB").hasClass("layui-form-item")) {
                                        $("#DAB").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    if ($("#CHC").hasClass("layui-form-item")) {
                                        $("#CHC").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    if ($("#STO").hasClass("layui-form-item")) {
                                        $("#STO").toggleClass("layui-form-item").toggleClass("hideinput");
                                    }
                                    //mqtt的参数
                                    if ($("#MQTTHostName").hasClass("topinput")) {
                                        $("#MQTTHostName").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTPort").hasClass("topinput")) {
                                        $("#MQTTPort").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTClientID").hasClass("topinput")) {
                                        $("#MQTTClientID").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTUsername").hasClass("topinput")) {
                                        $("#MQTTUsername").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTSubscribe").hasClass("topinput")) {
                                        $("#MQTTSubscribe").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTPublish").hasClass("topinput")) {
                                        $("#MQTTPublish").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#MQTTAccessKey").hasClass("topinput")) {
                                        $("#MQTTAccessKey").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    //modbus
                                    if ($("#ModbusTCPIP").hasClass("topinput")) {
                                        $("#ModbusTCPIP").toggleClass("topinput").toggleClass("hideinput");
                                    }
                                    if ($("#ModbusTCPPORT").hasClass("topinput")) {
                                        $("#ModbusTCPPORT").toggleClass("topinput").toggleClass("hideinput");
                                    }

                                    if ($("#IP").attr("lay-verify") === undefined) {
                                        $("#IP").attr("lay-verify", "required");
                                    }
                                    if ($("#PORT").attr("lay-verify") === undefined) {
                                        $("#PORT").attr("lay-verify", "required");
                                    }
                                    if ($("#DeviceInfoID").attr("lay-verify") !== undefined) {
                                        $("#DeviceInfoID").removeAttr('lay-verify');
                                    }
                                    $('#DeviceInfoID').attr("disabled", true)


                                }
                                //  layer.msg(this.innerHTML + ' 的 value: ' + value); // this 为当前选中 <option> 元素对象
                            });
                            if (options.ApplicationLayerProtocol === "3" || options.ApplicationLayerProtocol === "4" || options.ApplicationLayerProtocol === "5") {
                                //mqtt
                                ChangeSelectDisabled(true)
                            }
                            else if (options.ApplicationLayerProtocol === "6") {
                                $('#DeviceInfoID').attr("disabled", true)
                            }
                            else {
                                ChangeSelectDisabled(false)
                            }
                            // 提交事件
                            form.on('submit(submit)', function (data) {
                                var field = data.field; // 获取表单字段值
                                // 显示填写结果，仅作演示用
                                field.ID = parseInt(field.ID)
                                field.TransportLayerProtocol = parseInt(field.TransportLayerProtocol)
                                field.IsReportedData = parseInt(field.IsReportedData)
                                field.ApplicationLayerProtocol = parseInt(field.ApplicationLayerProtocol)
                                field.OHRT = parseInt(field.OHRT)
                                field.SPITV = parseInt(field.SPITV)
                                var ip = field.IP
                                var regexIP = /^((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))$/;
                                if (field.ApplicationLayerProtocol !== 3 && field.ApplicationLayerProtocol !== 4 && field.ApplicationLayerProtocol !== 5 && !regexIP.test(ip)) {
                                    layer.msg("远程主机地址有误，请重新输入！", {
                                        icon: 2
                                    });
                                    return false;
                                }

                                if (field.OHRT <= 0) {
                                    layer.msg("心跳周期必须大于0", {
                                        icon: 2
                                    });
                                    return false;
                                }
                                if (field.ApplicationLayerProtocol == 1) {
                                    if (field.SPITV <= 0) {
                                        layer.msg("数据传输周期必须大于0", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    field.OHRTCode = null
                                    field.ComName = null
                                    field.BAD = null
                                    field.DAB = null
                                    field.CHC = null
                                    field.STO = null

                                    //mqtt
                                    field.MQTTHostName = null
                                    field.MQTTPort = null
                                    field.MQTTClientID = null
                                    field.MQTTUsername = null
                                    field.MQTTSubscribe = null
                                    field.MQTTPublish = null
                                    field.MQTTAccessKey = null

                                    //modbus
                                    field.ModbusTCPIP = null
                                    field.ModbusTCPPORT = null
                                }
                                else if (field.ApplicationLayerProtocol == 2) {
                                    //mqtt
                                    field.MQTTHostName = null
                                    field.MQTTPort = null
                                    field.MQTTClientID = null
                                    field.MQTTUsername = null
                                    field.MQTTSubscribe = null
                                    field.MQTTPublish = null
                                    field.MQTTAccessKey = null
                                    //modbus
                                    field.ModbusTCPIP = null
                                    field.ModbusTCPPORT = null

                                    field.SPITV = 0
                                    field.BAD = parseInt(field.BAD)
                                    field.DAB = parseInt(field.DAB)
                                    field.CHC = parseInt(field.CHC)
                                    field.STO = parseInt(field.STO)
                                    if (field.OHRTCode == null || field.OHRTCode == '') {
                                        layer.msg("心跳命令码必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    if (field.ComName == null || field.ComName == '') {
                                        layer.msg("串口名称必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                }
                                else if (field.ApplicationLayerProtocol == 3 || field.ApplicationLayerProtocol == 4) {
                                    //mqtt
                                    field.OHRTCode = null
                                    field.ComName = null
                                    field.BAD = null
                                    field.DAB = null
                                    field.CHC = null
                                    field.STO = null
                                    //modbus
                                    field.ModbusTCPIP = null
                                    field.ModbusTCPPORT = null

                                    if (field.MQTTHostName == null || field.MQTTHostName == '') {
                                        layer.msg("HostName必填", {
                                            icon: 2
                                        });
                                        return false;
                                    } else if (field.MQTTHostName.indexOf("ssl://") == -1) {
                                        layer.msg("HostName格式必须为：ssl://xxxxxxxx", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    if (field.MQTTPort == null || field.MQTTPort == '') {
                                        layer.msg("Port必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    if (field.MQTTClientID == null || field.MQTTClientID == '') {
                                        layer.msg("ClientID必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    if (field.MQTTUsername == null || field.MQTTUsername == '') {
                                        layer.msg("Username必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    if (field.MQTTSubscribe == null || field.MQTTSubscribe == '') {
                                        layer.msg("Subscribe必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    if (field.MQTTPublish == null || field.MQTTPublish == '') {
                                        layer.msg("Publish必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    if (field.MQTTAccessKey == null || field.MQTTAccessKey == '') {
                                        layer.msg("AccessKey必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                }
                                else if (field.ApplicationLayerProtocol == 5) {
                                    field.OHRTCode = null
                                    field.ComName = null
                                    field.BAD = null
                                    field.DAB = null
                                    field.CHC = null
                                    field.STO = null
                                    //mqtt
                                    field.MQTTHostName = null
                                    field.MQTTPort = null
                                    field.MQTTClientID = null
                                    field.MQTTUsername = null
                                    field.MQTTSubscribe = null
                                    field.MQTTPublish = null
                                    field.MQTTAccessKey = null
                                    //modbus

                                    if (field.ModbusTCPIP == null || field.ModbusTCPIP == '') {
                                        layer.msg("Modbus_IP必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    if (field.ModbusTCPPORT == null || field.ModbusTCPPORT == '') {
                                        layer.msg("Modbus_PORT必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    if (field.SPITV2 == null || field.SPITV2 == '') {
                                        layer.msg("数据更新周期必填", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    field.SPITV = parseInt(field.SPITV2)
                                }
                                else if (field.ApplicationLayerProtocol == 6) {
                                    if (field.SPITV <= 0) {
                                        layer.msg("数据传输周期必须大于0", {
                                            icon: 2
                                        });
                                        return false;
                                    }
                                    field.OHRTCode = null
                                    field.ComName = null
                                    field.BAD = null
                                    field.DAB = null
                                    field.CHC = null
                                    field.STO = null

                                    //mqtt
                                    field.MQTTHostName = null
                                    field.MQTTPort = null
                                    field.MQTTClientID = null
                                    field.MQTTUsername = null
                                    field.MQTTSubscribe = null
                                    field.MQTTPublish = null
                                    field.MQTTAccessKey = null

                                    //modbus
                                    field.ModbusTCPIP = null
                                    field.ModbusTCPPORT = null
                                }
                                var obj = { DeviceInfo: field }
                                EditDeviceInfo(obj).then(function (responseData1) {
                                    //console.log('responseData1', responseData1)
                                    if (responseData1.code == 0) {
                                        form1()
                                    }
                                })

                                // location.reload();
                                return false; // 阻止默认 form 跳转
                            });
                            //删除串口
                            form.on('submit(deviceInfodelete)', function (data) {
                                layer.confirm('确认删除数据吗', function (index) {
                                    const postData = { DeviceInfolID: parseInt(options.id) };
                                    DeleteDeviceInfo(postData).then(function (responseData1) {
                                        form1()
                                        $('#right-form').empty();
                                        $('#Serial_Slave').empty();
                                    })
                                });
                                return false; // 阻止默认 form 跳转
                            });
                            //检测tcp连接
                            util.on('lay-on', {
                                'tcpsearch': function (a) {
                                    $("#icon").toggleClass("layui-icon-search").toggleClass("layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop");
                                    if ($("input[name='IP']").val() == null || $("input[name='IP']").val() == "" || $("input[name='IP']").val() == undefined) {
                                        layer.msg("测试连接的IP不能为空", {
                                            icon: 2
                                        });
                                        $("#icon").toggleClass("layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop").toggleClass("layui-icon-search");
                                        return
                                    } else if ($("input[name='PORT']").val() == null || $("input[name='PORT']").val() == "" || $("input[name='PORT']").val() == undefined) {
                                        layer.msg("测试连接的PORT不能为空", {
                                            icon: 2
                                        });
                                        $("#icon").toggleClass("layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop").toggleClass("layui-icon-search");
                                        return
                                    }
                                    const postData = { IP: $("input[name='IP']").val() + ":" + $("input[name='PORT']").val() };
                                    GetTcpConnect(postData).then(function (responseData) {
                                        // console.log("responseData", responseData)
                                        $("#icon").toggleClass("layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop").toggleClass("layui-icon-search");
                                    })
                                }
                            })
                            // document.getElementById("autoSpaceInput").addEventListener("input", function() {
                            //     console.log("2")
                            //     var value = this.value;
                            //     var newValue = value.replace(/\s/g, '').replace(/(.{2})/g, '$1 ');
                            //     this.value = newValue.trim();
                            //     console.log('newValue2',newValue)
                            //         document.getElementById("autoSpaceInput").value = newValue;
                            // });
                        }
                        else if (options.title != null && options.title == "配置") {
                            form2(options, responseDatas)
                        }

                        else if (options.title == "新建集中器" || options.Level == 1) {
                            ConcentratorForm(options)
                        }
                        else if (options.title == "新建用户表" || options.Level == 2) {
                            // console.log("options111",options)
                            ConcentratorUserForm(options)
                            if (options.Level == 2) {
                                form2(options, responseDatas)
                            }
                        }
                        // layer.msg(util.escape(JSON.stringify(options)));
                    });

                })
                // 选择下拉框

                // });

            }
            //新建or修改集中器
            function ConcentratorForm(options) {
                // console.log('options', options)

                //点击地址位
                // 遍历数据，动态生成菜单项
                var html = '';
                // data.forEach(function (item) {
                html += `  <div class="layui-card-header"><h3>${options.Level == 1 ? "修改集中器" : "新建集中器"}</h3><span> 
                    ${options.Level == 1 ? `<button class="layui-btn  layui-btn-primary layui-border-red" lay-submit  lay-filter="DeleteConcentrator">
                        <i class="layui-icon layui-icon-delete"> </i>  删除
                    </button>`: ``} 
                    <button class="layui-btn layui-btn-primary layui-border-green" lay-submit  lay-filter="submitConcentrator">提交</button></span></div> 
                <div class="layui-tab" lay-filter="tab-hash">
                    <ul class="layui-tab-title">
                      <li class="layui-this" lay-id="0">基本信息</li>
                    </ul>
                    
                    <div class="layui-tab-content">
                      <div class="layui-tab-item layui-show">
                        <div class="layui-card-body">
                            <li class="layui-menu  layui-menu-item-divider"></li>
                            <div class="layui-form-item topinput">
                                <label class="layui-form-label required">名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="Name" autocomplete="off" placeholder="请输入" lay-verify="required"
                                        value='${options.Name}' class="layui-input inputtitle">
                                </div>
                            </div>
                            <div class="layui-form-item topinput">
                                <label class="layui-form-label">描述</label>
                                <div class="layui-input-block">
                                    <input type="text" name="Describe" autocomplete="off" placeholder="请输入" 
                                    value='${options.Describe}' class="layui-input inputtitle">
                                   
                                </div>
                            </div>                                
                            <div class="layui-form-item topinput">
                                <label class="layui-form-label required">集中器地址</label>
                                <div class="layui-input-block">
                                    <input  name="Dev" autocomplete="off" placeholder="请输入" lay-verify="required"
                                       value='${options.Dev}' class="layui-input inputtitle">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                `
                // });
                $('#Serial_Slave').append(html);
                form.render();
                // 提交事件
                form.on('submit(submitConcentrator)', function (data) {
                    var field = data.field; // 获取表单字段值
                    field.Device_ID = parseInt(options.Device_ID)
                    field.ID = parseInt(options.ID)

                    var obj = { DeviceInfo_Concentrator: field }
                    EditDeviceInfo_Concentrator(obj).then(function (responseData1) {
                        if (responseData1.success) {
                            form1()
                        } else {
                            return false
                        }
                    })

                    // location.reload();
                    return false; // 阻止默认 form 跳转
                });
                //删除集中器
                form.on('submit(DeleteConcentrator)', function (data) {
                    layer.confirm('确认删除集中器数据吗', function (index) {
                        const postData = { ConcentratorID: parseInt(options.ID) };
                        DeleteConcentrator(postData).then(function (responseData1) {
                            form1()
                            $('#right-form').empty();
                            $('#Serial_Slave').empty();
                        })
                    });
                    return false; // 阻止默认 form 跳转
                });
                //  })
            }
            //新建or修改用户表
            function ConcentratorUserForm(options) {
                // console.log('options', options)

                //点击地址位
                // 遍历数据，动态生成菜单项
                var html = '';
                // data.forEach(function (item) {
                html += `  <div class="layui-card-header"><h3>${options.Level == 2 ? "修改用户表" : "新建用户表"}</h3><span> 
                    ${options.Level == 2 ? `<button class="layui-btn  layui-btn-primary layui-border-red" lay-submit  lay-filter="DeleteConcentratorUser">
                        <i class="layui-icon layui-icon-delete"> </i>  删除
                    </button>`: ``} 
                    <button class="layui-btn layui-btn-primary layui-border-green" lay-submit  lay-filter="submitConcentratorUser">提交</button></span></div> 
                <div class="layui-tab" lay-filter="tab-hash">
                    <ul class="layui-tab-title">
                      <li class="layui-this" lay-id="0">基本信息</li>
                    </ul>
                    
                    <div class="layui-tab-content">
                      <div class="layui-tab-item layui-show">
                        <div class="layui-card-body">
                            <li class="layui-menu  layui-menu-item-divider"></li>
                            <div class="layui-form-item topinput">
                                <label class="layui-form-label required">名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="Name" autocomplete="off" placeholder="请输入" lay-verify="required"
                                        value='${options.Name}' class="layui-input inputtitle">
                                </div>
                            </div>
                            <div class="layui-form-item topinput">
                                <label class="layui-form-label">描述</label>
                                <div class="layui-input-block">
                                    <input type="text" name="Describe" autocomplete="off" placeholder="请输入" 
                                    value='${options.Describe}' class="layui-input inputtitle">
                                   
                                </div>
                            </div>                                
                            <div class="layui-form-item topinput">
                                <label class="layui-form-label required">表地址</label>
                                <div class="layui-input-block">
                                    <input  name="Mn" autocomplete="off" placeholder="请输入" lay-verify="required"
                                       value='${options.Mn}' class="layui-input inputtitle">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                `
                // });
                $('#Serial_Slave').append(html);
                form.render();
                // 提交事件
                form.on('submit(submitConcentratorUser)', function (data) {
                    var field = data.field; // 获取表单字段值
                    field.Device_ID = parseInt(options.Device_ID)
                    field.ID = parseInt(options.ID)
                    field.DeviceInfo_Concentrator_ID = parseInt(options.DeviceInfo_Concentrator_ID)
                    var obj = { DeviceInfo_Concentrator_User: field }
                    EditDeviceInfo_Concentrator_User(obj).then(function (responseData1) {
                        if (responseData1.success) {
                            form1()
                        } else {
                            return false
                        }
                    })

                    // location.reload();
                    return false; // 阻止默认 form 跳转
                });
                //删除集中器-用户表
                form.on('submit(DeleteConcentratorUser)', function (data) {
                    layer.confirm('确认删除用户表数据吗', function (index) {
                        const postData = { ConcentratorUserID: parseInt(options.ID) };
                        DeleteConcentratorUser(postData).then(function (responseData1) {
                            form1()
                            $('#right-form').empty();
                            $('#Serial_Slave').empty();
                        })
                    });
                    return false; // 阻止默认 form 跳转
                });
                //  })
            }

            function form2(options, responseDatas) {
                console.log("options", options)
                var meterAddressInits = 2;
                util.on('lay-on', {
                    'test-offset': function () {
                        var othis = $(this);
                        var id = othis.data('id');
                        var tableConfigsS = tableConfigs[0]
                        // console.log("othis", othis)
                        if (options.ApplicationLayerProtocol === "5") {//modbus
                            if (tabType == 3) {//功能码1
                                tableConfigsS = tableConfigs[3]
                                selectEdit(id, tree, responseDatas, tableConfigsS, modbusdata1, table)
                            } else if (tabType == 4) {
                                tableConfigsS = tableConfigs[4]
                                selectEdit(id, tree, responseDatas, tableConfigsS, modbusdata2, table)
                            } else if (tabType == 5) {
                                tableConfigsS = tableConfigs[5]
                                selectEdit(id, tree, responseDatas, tableConfigsS, modbusdata3, table)
                            } else if (tabType == 6) {
                                tableConfigsS = tableConfigs[6]
                                selectEdit(id, tree, responseDatas, tableConfigsS, modbusdata4, table)
                            }
                        }
                        else if (options.ApplicationLayerProtocol === "6") {//集中器                   
                            if (concentratorType == 1) {
                                tableConfigsS = tableConfigs[7]
                                selectEdit(id, tree, responseDatas, tableConfigsS, Concentratordata1, table)
                            }
                            else if (concentratorType == 2) {
                                tableConfigsS = tableConfigs[8]
                                console.log("Concentratordata22", Concentratordata2)
                                selectEdit(id, tree, responseDatas, tableConfigsS, Concentratordata2, table)
                            }
                            else if (concentratorType == 3) {
                                tableConfigsS = tableConfigs[9]
                                selectEdit(id, tree, responseDatas, tableConfigsS, Concentratordata3, table)
                            }
                        }
                        else {
                            if (options.ApplicationLayerProtocol === "3") {
                                tableConfigsS = tableConfigs[1]
                            } else if (options.ApplicationLayerProtocol === "4") {
                                tableConfigsS = tableConfigs[2]
                            }
                            selectEdit(id, tree, responseDatas, tableConfigsS, dataList3, table)
                        }

                    },
                    getTime1: function (ohtis) {
                        var address = meterAddressInits
                        var maxID = 1;
                        dataList3.forEach(dataItem => {
                            if (dataItem.ID <= 0) {
                                if (maxID > dataItem.ID) {
                                    maxID = dataItem.ID
                                }
                            }
                        });
                        maxID = maxID - 1
                        var dataCopy = {
                            ID: maxID--,
                            Device_ID: options.id,
                            Serial_ID: -1,
                            Serial_Slave_ID: -1,
                            Serial_Slave_Detail_ID: -1,
                            Name: '',
                            MeterAddress: address,
                            CollectName: '时间戳.秒'
                        };
                        dataList3.push(dataCopy);
                        if (options.ApplicationLayerProtocol == "4") {
                            table.reload("optionsMqttsOneNet", optionsMqttsOneNet, true);
                        }

                        layer.closeAll()
                    },
                    getTime2: function (ohtis) {
                        var address = meterAddressInits
                        var maxID = 1;
                        dataList3.forEach(dataItem => {
                            if (dataItem.ID <= 0) {
                                if (maxID > dataItem.ID) {
                                    maxID = dataItem.ID
                                }
                            }
                        });
                        maxID = maxID - 1
                        var dataCopy = {
                            ID: maxID--,
                            Device_ID: options.id,
                            Serial_ID: -2,
                            Serial_Slave_ID: -2,
                            Serial_Slave_Detail_ID: -2,
                            Name: '',
                            MeterAddress: address,
                            CollectName: '时间戳.毫秒'
                        };
                        dataList3.push(dataCopy);
                        if (options.ApplicationLayerProtocol == "4") {
                            table.reload("optionsMqttsOneNet", optionsMqttsOneNet, true);
                        }

                        layer.closeAll()
                    },
                    getChecked: function (othis) {
                        //console.log("asd",dataList3)
                        var maxID = 1;
                        dataList3.forEach(dataItem => {
                            if (dataItem.ID <= 0) {
                                if (maxID > dataItem.ID) {
                                    maxID = dataItem.ID
                                }
                            }
                        });
                        maxID = maxID - 1
                        if (options.ApplicationLayerProtocol == "1") {
                            var dataList = table.getData("serialSlaveDetail3");
                            console.log("dataList", dataList)
                            dataList.forEach(dataItem => {
                                if (dataItem <= 0) {
                                    maxID -= 1
                                }
                            });
                        }
                        // console.log('maxID', maxID)
                        var checkedData = tree.getChecked('treeSelect'); // 获取选中节点的数据
                        //layer.alert(JSON.stringify(checkedData), { shade: 0 });
                        //console.log("checkedData", checkedData)
                        var lastData = findSerialSlaveIDNotZero(checkedData)
                        // console.log("lastData", lastData)
                        if (lastData.length == 0) {
                            layer.msg("未选择有效数据", {
                                icon: 2
                            });
                            return
                        }
                        var address = meterAddressInits
                        lastData.forEach(item => {
                            var dataCopy = {

                                ID: maxID--,
                                Device_ID: options.id,
                                Serial_ID: item.serialID,
                                Serial_Slave_ID: item.serialSlaveID,
                                Serial_Slave_Detail_ID: item.id,
                                Name: '',
                                MeterAddress: address,
                                CollectName: item.title,
                                MqttStep: 0
                            };
                            if (options.ApplicationLayerProtocol != "5" && options.ApplicationLayerProtocol != "6") {
                                dataList3.push(dataCopy);
                            } else if (options.ApplicationLayerProtocol == "5") { //modbus

                                dataCopy.ModbusTCPSlaveID = "1";
                                dataCopy.ModbusTCPAddressID = 1;
                                if (tabType == 3) {
                                    dataCopy.ModbusTCPType = 1;
                                    modbusdata1.push(dataCopy);
                                }
                                else if (tabType == 4) {
                                    dataCopy.ModbusTCPType = 2;
                                    modbusdata2.push(dataCopy);
                                }
                                else if (tabType == 5) {
                                    dataCopy.ModbusTCPType = 3;
                                    modbusdata3.push(dataCopy);
                                }
                                else if (tabType == 6) {
                                    dataCopy.ModbusTCPType = 4;
                                    modbusdata4.push(dataCopy);
                                }
                            } else if (options.ApplicationLayerProtocol == "6") { //四表集中器
                                dataCopy.ConcentratorType = concentratorType
                                if (concentratorType == 1) {
                                    Concentratordata1.push(dataCopy);
                                }
                                else if (concentratorType == 2) {
                                    Concentratordata2.push(dataCopy);
                                }
                                else if (concentratorType == 3) {
                                    Concentratordata3.push(dataCopy);
                                }
                            }
                            address++

                        });
                        if (options.ApplicationLayerProtocol == "1") {
                            table.reload("serialSlaveDetail3", options3, true);
                        }
                        else if (options.ApplicationLayerProtocol == "3") {
                            table.reload("optionsMqtts", optionsMqtts, true);
                        }
                        else if (options.ApplicationLayerProtocol == "4") {
                            table.reload("optionsMqttsOneNet", optionsMqttsOneNet, true);
                        }
                        else if (options.ApplicationLayerProtocol == "5") {
                            if (tabType == 3) {
                                table.reload("Modbus1", optionsmodbus1, true);
                            }
                            else if (tabType == 4) {
                                table.reload("Modbus2", optionsmodbus2, true);
                            }
                            else if (tabType == 5) {
                                table.reload("Modbus3", optionsmodbus3, true);
                            }
                            else if (tabType == 6) {
                                table.reload("Modbus4", optionsmodbus4, true);
                            }
                        }
                        else if (options.ApplicationLayerProtocol == "6") {
                            if (concentratorType == 1) {
                                table.reload("ConcentratorType1", optionsConcentratorType1, true);
                            }
                            else if (concentratorType == 2) {
                                table.reload("ConcentratorType2", optionsConcentratorType2, true);
                            }
                            else if (concentratorType == 3) {
                                table.reload("ConcentratorType3", optionsConcentratorType3, true);
                            }
                        }
                        layer.closeAll()
                    }

                });

                //点击地址位
                // 遍历数据，动态生成菜单项
                var html = '';
                // data.forEach(function (item) {
                console.log("options.ApplicationLayerProtocol", options.ApplicationLayerProtocol)
                html += `  <div class="layui-card-header"><h3>配置</h3>
                    <span> 
                        <button class="layui-btn layui-btn-primary layui-border-green" lay-submit  lay-filter="save">保存</button>
                    <span></div> 
                <div class="layui-tab" lay-filter="tab-hash">
                    <ul class="layui-tab-title">
                      <li class="layui-this"    ${options.ApplicationLayerProtocol == "1" ? "" : 'style="display: none;"'}  lay-id="0">遥信点</li>
                      <li class="layui-this"    ${options.ApplicationLayerProtocol == "3" ? "" : 'style="display: none;"'}  lay-id="1">配置</li>
                      <li class="layui-this"    ${options.ApplicationLayerProtocol == "4" ? "" : 'style="display: none;"'}  lay-id="2">配置</li>
                      <li class="layui-this"    ${options.ApplicationLayerProtocol == "5" ? "" : 'style="display: none;"'}  lay-id="3">功能码1</li>
                      <li     ${options.ApplicationLayerProtocol == "5" ? "" : 'style="display: none;"'}  lay-id="4">功能码2</li>
                      <li     ${options.ApplicationLayerProtocol == "5" ? "" : 'style="display: none;"'}  lay-id="5">功能码3</li>
                      <li     ${options.ApplicationLayerProtocol == "5" ? "" : 'style="display: none;"'}  lay-id="6">功能码4</li>
                      <li class="layui-this"    ${options.ApplicationLayerProtocol == "6" ? "" : 'style="display: none;"'}  lay-id="7">水表</li>
                      <li     ${options.ApplicationLayerProtocol == "6" ? "" : 'style="display: none;"'}  lay-id="8">电表</li>
                      <li     ${options.ApplicationLayerProtocol == "6" ? "" : 'style="display: none;"'}  lay-id="9">流量计</li>
                    </ul>
                    
                    <div class="layui-tab-content">  
                        <div class="layui-tab-item  ${options.ApplicationLayerProtocol == "1" ? "layui-show" : ""}"><table class="layui-hide" id="serialSlaveDetail3" lay-filter="serialSlaveDetail3"></table></div>
                        <div class="layui-tab-item  ${options.ApplicationLayerProtocol == "3" ? "layui-show" : ""}"><table class="layui-hide" id="optionsMqtts"></table></div>
                        <div class="layui-tab-item  ${options.ApplicationLayerProtocol == "4" ? "layui-show" : ""}"><table class="layui-hide" id="optionsMqttsOneNet"></table></div>
                        <div class="layui-tab-item  ${options.ApplicationLayerProtocol == "5" ? "layui-show" : ""}"><table class="layui-hide" id="Modbus1" lay-filter="Modbus1"></table></div>
                        <div class="layui-tab-item"><table class="layui-hide" id="Modbus2"></table></div>
                        <div class="layui-tab-item"><table class="layui-hide" id="Modbus3"></table></div>
                        <div class="layui-tab-item"><table class="layui-hide" id="Modbus4"></table></div>
                        <div class="layui-tab-item  ${options.ApplicationLayerProtocol == "6" ? "layui-show" : ""}"><table class="layui-hide" id="ConcentratorType1"></table></div>
                        <div class="layui-tab-item"><table class="layui-hide" id="ConcentratorType2"></table></div>
                        <div class="layui-tab-item"><table class="layui-hide" id="ConcentratorType3"></table></div>
                        </div>
                  </div>`
                // });
                $('#Serial_Slave').append(html);

                // 已知数据渲染
                var tabType = 3; //默认功能码1
                var concentratorType = 1;//集中器 默认1：水表
                var dataList3 = []
                var modbusdata1 = []
                var modbusdata2 = []
                var modbusdata3 = []
                var modbusdata4 = []
                var Concentratordata1 = []
                var Concentratordata2 = []
                var Concentratordata3 = []
                function processData(data, type, dataList) {
                    console.log("data", data)
                    data.forEach(function (item) {

                        if (options.id == item.ID) {

                            item.DeviceInfo_Detail.forEach(function (item1) {


                                if (type == -1) {
                                    dataList.push(item1);
                                } else {
                                    if (item.ApplicationLayerProtocol == 6) {

                                        if (item1.ConcentratorType == type && item1.DeviceInfo_Concentrator_User_ID == options.DeviceInfo_Concentrator_User_ID) {
                                            console.log("6", item1)
                                            dataList.push(item1);
                                        }
                                    }
                                    else {
                                        if (item1.ModbusTCPType != null && item1.ModbusTCPType === type) {
                                            dataList.push(item1);
                                        }
                                    }
                                }

                            });
                        }

                    });
                }
                console.log("options2", options)

                if (options.ApplicationLayerProtocol === "5") {
                    processData(data, 1, modbusdata1);
                    processData(data, 2, modbusdata2);
                    processData(data, 3, modbusdata3);
                    processData(data, 4, modbusdata4);
                }
                else if (options.ApplicationLayerProtocol === "6") {
                    processData(data, 1, Concentratordata1);
                    processData(data, 2, Concentratordata2);
                    processData(data, 3, Concentratordata3);
                } else {
                    processData(data, -1, dataList3);
                }
                var cols = [[ //标题栏
                    //{checkbox: true, fixed: true},
                    { field: 'ID', title: 'ID', width: 20, sort: true },
                    { title: '采集点名', templet: '#treeh' },
                    { field: 'Name', title: '变量名', width: 300, edit: 'text' },
                    { field: 'ModbusTCPSlaveID', title: '设备地址', width: 120, edit: 'text' },
                    { field: 'ModbusTCPAddressID', title: '寄存器地址', width: 120, edit: 'text' },
                    // { field: 'Device_ID', title: 'Device_ID', width: 200, edit: 'text' },
                    // { field: 'Serial_Slave_Detail_ID', title: 'Serial_Slave_Detail_ID', width: 100, edit: 'text' },
                    { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#templet-demo-theads-tool' }
                ]];
                var optionsmodbus1 = {
                    toolbar: '#toolbarDemo',
                    elem: '#Modbus1',
                    css: [
                        // 对开启了编辑的单元格追加样式
                        '.layui-table-view td[data-edit]{color: #16B777;}'
                    ].join(''),
                    cols: cols,
                    data: modbusdata1,
                    page: false, // 是否显示分页
                }
                var optionsmodbus2 = {
                    toolbar: '#toolbarDemo',
                    elem: '#Modbus2',
                    css: [
                        // 对开启了编辑的单元格追加样式
                        '.layui-table-view td[data-edit]{color: #16B777;}'
                    ].join(''),
                    cols: cols,
                    data: modbusdata2,
                    page: false, // 是否显示分页
                }
                var optionsmodbus3 = {
                    toolbar: '#toolbarDemo',
                    elem: '#Modbus3',
                    css: [
                        // 对开启了编辑的单元格追加样式
                        '.layui-table-view td[data-edit]{color: #16B777;}'
                    ].join(''),
                    cols: cols,
                    data: modbusdata3,
                    page: false, // 是否显示分页
                }
                var optionsmodbus4 = {
                    toolbar: '#toolbarDemo',
                    elem: '#Modbus4',
                    css: [
                        // 对开启了编辑的单元格追加样式
                        '.layui-table-view td[data-edit]{color: #16B777;}'
                    ].join(''),
                    cols: cols,
                    data: modbusdata4,
                    page: false, // 是否显示分页
                }
                //集中器
                var optionsConcentratorType1 = {
                    toolbar: '#toolbarDemo',
                    elem: '#ConcentratorType1',
                    css: [
                        // 对开启了编辑的单元格追加样式
                        '.layui-table-view td[data-edit]{color: #16B777;}'
                    ].join(''),
                    cols: [[ //集中器
                    //{checkbox: true, fixed: true},
                    { field: 'ID', title: 'ID', width: 20, sort: true },
                    { title: '采集点名', templet: '#treeh' },
                    { field: 'Name', title: '变量名', width: 300, edit: 'text' },
                    //{ field: 'ConcentratorKey', title: '数据标识', width: 120, edit: 'text' },
                    {
                        field: 'ConcentratorKey', title: '数据标识', width: 180, style: 'overflow: unset;',//height:100%
                        //templet: '#dataChange'
                        templet: function (d) {
                            return `
                        <div class="layui-form">
                            <select  id="ConcentratorKey`+ d.ID + `">                
                               <option value="IF" ${d.ConcentratorKey === "IF" ? 'selected' : ''}>瞬时流量</option>                               
                               <option value="FAcc" ${d.ConcentratorKey === "FAcc" ? 'selected' : ''}>正向流量</option>      
                               <option value="RAcc" ${d.ConcentratorKey === "RAcc" ? 'selected' : ''}>反向流量</option>      
                               <option value="Vol" ${d.ConcentratorKey === "Vol" ? 'selected' : ''}>电池电压</option>      
                               <option value="Valve" ${d.ConcentratorKey === "Valve" ? 'selected' : ''}>阀门状态</option>  
                               <option value="ST" ${d.ConcentratorKey === "ST" ? 'selected' : ''}>运行状态</option>      
                            </select>        
                        </div>
                         `;
                        }
                    },
                    // { field: 'Device_ID', title: 'Device_ID', width: 200, edit: 'text' },
                    // { field: 'Serial_Slave_Detail_ID', title: 'Serial_Slave_Detail_ID', width: 100, edit: 'text' },
                    { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#templet-demo-theads-tool' }
                ]],
                    data: Concentratordata1,
                    lineStyle: 'height: 50px;',
                    height: 500,
                    page: false, // 是否显示分页
                }
                var optionsConcentratorType2 = {
                    toolbar: '#toolbarDemo',
                    elem: '#ConcentratorType2',
                    css: [
                        // 对开启了编辑的单元格追加样式
                        '.layui-table-view td[data-edit]{color: #16B777;}'
                    ].join(''),
                    cols: [[ //集中器
                    //{checkbox: true, fixed: true},
                    { field: 'ID', title: 'ID', width: 20, sort: true },
                    { title: '采集点名', templet: '#treeh' },
                    { field: 'Name', title: '变量名', width: 300, edit: 'text' },
                   // { field: 'ConcentratorKey', title: '数据标识', width: 120, edit: 'text' },
                    {
                        field: 'ConcentratorKey', title: '数据标识', width: 180, style: 'overflow: unset;',//height:100%
                        //templet: '#dataChange'
                        templet: function (d) {
                            return `                       
                        <div class="layui-form">
                            <select  id="ConcentratorKey`+ d.ID + `">                
                               <option value="AV" ${d.ConcentratorKey === "AV" ? 'selected' : ''}>A相电压</option>                               
                               <option value="BV" ${d.ConcentratorKey === "BV" ? 'selected' : ''}>B相电压</option>      
                               <option value="CV" ${d.ConcentratorKey === "CV" ? 'selected' : ''}>C相电压</option>      
                               <option value="AC" ${d.ConcentratorKey === "AC" ? 'selected' : ''}>A相电流</option>      
                               <option value="BC" ${d.ConcentratorKey === "BC" ? 'selected' : ''}>B相电流</option>  
                               <option value="CC" ${d.ConcentratorKey === "CC" ? 'selected' : ''}>C相电流</option>  
                               <option value="Frequency" ${d.ConcentratorKey === "Frequency" ? 'selected' : ''}>频率</option>  
                               <option value="PowerFactor" ${d.ConcentratorKey === "PowerFactor" ? 'selected' : ''}>功率因素</option>  
                               <option value="FAcc" ${d.ConcentratorKey === "FAcc" ? 'selected' : ''}>正向有功总电能</option>  
                               <option value="RAcc" ${d.ConcentratorKey === "RAcc" ? 'selected' : ''}>反向有功总电能</option>      
                               <option value="Sharp" ${d.ConcentratorKey === "Sharp" ? 'selected' : ''}>尖</option>  
                               <option value="Peak" ${d.ConcentratorKey === "Peak" ? 'selected' : ''}>峰</option>  
                               <option value="Flat" ${d.ConcentratorKey === "Flat" ? 'selected' : ''}>平</option>  
                               <option value="Valley" ${d.ConcentratorKey === "Valley" ? 'selected' : ''}>谷</option>  
                               <option value="FNAcc" ${d.ConcentratorKey === "FNAcc" ? 'selected' : ''}>正向无功总电能</option>  
                               <option value="RNAcc" ${d.ConcentratorKey === "RNAcc" ? 'selected' : ''}>反向无功总电能</option>  
                               <option value="APower" ${d.ConcentratorKey === "APower" ? 'selected' : ''}>有功功率</option>  
                               <option value="RPower" ${d.ConcentratorKey === "RPower" ? 'selected' : ''}>无功功率</option>  
                               <option value="Vol" ${d.ConcentratorKey === "Vol" ? 'selected' : ''}>电池电压</option>  
                               <option value="Valve" ${d.ConcentratorKey === "Valve" ? 'selected' : ''}>阀门状态</option>  
                               <option value="ST" ${d.ConcentratorKey === "ST" ? 'selected' : ''}>运行状态</option>  
                            </select>        
                        </div>
                         `;
                        }
                    },
                    // { field: 'Device_ID', title: 'Device_ID', width: 200, edit: 'text' },
                    // { field: 'Serial_Slave_Detail_ID', title: 'Serial_Slave_Detail_ID', width: 100, edit: 'text' },
                    { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#templet-demo-theads-tool' }
                ]],
                    data: Concentratordata2,
                    lineStyle: 'height: 50px;',
                    height: 500,
                    page: false, // 是否显示分页
                }
                var optionsConcentratorType3 = {
                    toolbar: '#toolbarDemo',
                    elem: '#ConcentratorType3',
                    css: [
                        // 对开启了编辑的单元格追加样式
                        '.layui-table-view td[data-edit]{color: #16B777;}'
                    ].join(''),
                    cols: [[ //集中器
                    //{checkbox: true, fixed: true},
                    { field: 'ID', title: 'ID', width: 20, sort: true },
                    { title: '采集点名', templet: '#treeh' },
                    { field: 'Name', title: '变量名', width: 300, edit: 'text' },
                   // { field: 'ConcentratorKey', title: '数据标识', width: 120, edit: 'text' },
                    {
                        field: 'ConcentratorKey', title: '数据标识', width: 180, style: 'overflow: unset;',//height:100%
                        //templet: '#dataChange'
                        templet: function (d) {
                            return `                       
                        <div class="layui-form">
                            <select  id="ConcentratorKey`+ d.ID + `">                
                               <option value="IF" ${d.ConcentratorKey === "IF" ? 'selected' : ''}>瞬时流量</option>                               
                               <option value="FAcc" ${d.ConcentratorKey === "FAcc" ? 'selected' : ''}>正向流量</option>      
                               <option value="RAcc" ${d.ConcentratorKey === "RAcc" ? 'selected' : ''}>反向流量</option> 
                               <option value="Press" ${d.ConcentratorKey === "Press" ? 'selected' : ''}>压力</option>        
                               <option value="Vol" ${d.ConcentratorKey === "Vol" ? 'selected' : ''}>电池电压</option>      
                               <option value="Valve" ${d.ConcentratorKey === "Valve" ? 'selected' : ''}>阀门状态</option>  
                               <option value="ST" ${d.ConcentratorKey === "ST" ? 'selected' : ''}>运行状态</option>      
                            </select>        
                        </div>                         
                         `;
                        }
                    },
                    // { field: 'Device_ID', title: 'Device_ID', width: 200, edit: 'text' },
                    // { field: 'Serial_Slave_Detail_ID', title: 'Serial_Slave_Detail_ID', width: 100, edit: 'text' },
                    { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#templet-demo-theads-tool' }
                ]],
                    data: Concentratordata3,
                    lineStyle: 'height: 50px;',
                    height: 500,
                    page: false, // 是否显示分页
                }
                1

                var options3 = {
                    toolbar: '#toolbarDemo',
                    elem: '#serialSlaveDetail3',
                    css: [
                        // 对开启了编辑的单元格追加样式
                        '.layui-table-view td[data-edit]{color: #16B777;}'
                    ].join(''),
                    cols: [[ //标题栏
                        //{checkbox: true, fixed: true},
                        { field: 'ID', title: 'ID', width: 20, sort: true },
                        // { field: 'CollectName', title: '采集点名'},
                        { title: '采集点名', templet: '#treeh' },
                        { field: 'Name', title: '变量名', width: 300, edit: 'text' },
                        { field: 'MeterAddress', title: '点号', width: 150, edit: 'text' },
                        // { field: 'Device_ID', title: 'Device_ID', width: 200, edit: 'text' },
                        // { field: 'Serial_Slave_Detail_ID', title: 'Serial_Slave_Detail_ID', width: 100, edit: 'text' },
                        { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#templet-demo-theads-tool' }
                    ]],

                    data: dataList3,
                    page: false, // 是否显示分页
                }
                var optionsMqtts = {
                    toolbar: '#toolbarDemo',
                    elem: '#optionsMqtts',
                    css: [
                        // 对开启了编辑的单元格追加样式
                        '.layui-table-view td[data-edit]{color: #16B777;}'
                    ].join(''),
                    cols: [[ //标题栏
                        //{checkbox: true, fixed: true},
                        { field: 'ID', title: 'ID', width: 20, sort: true },
                        // { field: 'CollectName', title: '采集点名'},
                        { title: '累计水量ACCW', templet: '#treeh', width: 200 },
                        { field: 'Name', title: '变量名', edit: 'text' },
                        //  { field: 'MeterAddress', title: '点号', width: 150, edit: 'text' },
                        { field: 'STCD', title: '测站编码', width: 150, edit: 'text' },
                        { field: 'MPCD', title: '测点编码', width: 150, edit: 'text' },
                        // { field: 'Device_ID', title: 'Device_ID', width: 200, edit: 'text' },
                        // { field: 'Serial_Slave_Detail_ID', title: 'Serial_Slave_Detail_ID', width: 100, edit: 'text' },
                        { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#templet-demo-theads-tool' }
                    ]],

                    data: dataList3,
                    page: false, // 是否显示分页
                }
                var optionsMqttsOneNet = {
                    toolbar: '#toolbarDemo',
                    elem: '#optionsMqttsOneNet',
                    css: [
                        // 对开启了编辑的单元格追加样式
                        '.layui-table-view td[data-edit]{color: #16B777;}'
                    ].join(''),
                    cols: [[ //标题栏
                        //{checkbox: true, fixed: true},
                        { field: 'ID', title: 'ID', width: 20, sort: true },
                        { title: '上传参数值', templet: '#treeh', width: 200 },
                        { field: 'MqttKey', title: '上传标识', width: 150, edit: 'text' },
                        // { field: 'MqttDataType', title: '数据类型', width: 150, edit: 'text' },
                        {
                            field: 'MqttDataType', title: '数据类型', width: 180, style: 'overflow: unset;',//height:100%
                            //templet: '#dataChange'
                            templet: function (d) {
                                return `
                        <div class="layui-form"></div>
                            <select id="MqttDataType`+ d.ID + `">                
                               <option value="1" ${d.MqttDataType === 1 ? 'selected' : ''}>float</option>                               
                               <option value="2" ${d.MqttDataType === 2 ? 'selected' : ''}>double</option>      
                               <option value="3" ${d.MqttDataType === 3 ? 'selected' : ''}>int</option>      
                               <option value="4" ${d.MqttDataType === 4 ? 'selected' : ''}>string</option>      
                               <option value="5" ${d.MqttDataType === 5 ? 'selected' : ''}>date</option>      
                            </select>        
                         </div>`;
                            }
                        },
                        { field: 'MqttStep', title: '小数点位数', width: 150, edit: 'text' },
                        { field: 'Name', title: '变量名', edit: 'text' },
                        { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#templet-demo-theads-tool' }
                    ]],
                    lineStyle: 'height: 50px;',
                    height: 500,
                    data: dataList3,
                    page: false, // 是否显示分页
                }
                var tableConfigs = [
                    {
                        elem: '#serialSlaveDetail3',
                        options: options3,
                        dataList: dataList3,
                        type: -1
                    },
                    {
                        elem: '#optionsMqtts',
                        options: optionsMqtts,
                        dataList: dataList3,
                        type: -1
                    },
                    {
                        elem: '#optionsMqttsOneNet',
                        options: optionsMqttsOneNet,
                        dataList: dataList3,
                        type: -1
                    },
                    {
                        elem: '#Modbus1',
                        options: optionsmodbus1,
                        dataList: modbusdata1,
                        type: 1
                    },
                    {
                        elem: '#Modbus2',
                        options: optionsmodbus2,
                        dataList: modbusdata2,
                        type: 2
                    },
                    {
                        elem: '#Modbus3',
                        options: optionsmodbus3,
                        dataList: modbusdata3,
                        type: 3
                    },
                    {
                        elem: '#Modbus4',
                        options: optionsmodbus4,
                        dataList: modbusdata4,
                        type: 4
                    },
                    {
                        elem: '#ConcentratorType1',
                        options: optionsConcentratorType1,
                        dataList: Concentratordata1,
                        type: 1
                    },
                    {
                        elem: '#ConcentratorType2',
                        options: optionsConcentratorType2,
                        dataList: Concentratordata2,
                        type: 2
                    },
                    {
                        elem: '#ConcentratorType3',
                        options: optionsConcentratorType3,
                        dataList: Concentratordata3,
                        type: 3
                    },
                ];
                element.on('tab(tab-hash)', function (data) {

                    tabType = data.index
                    concentratorType = data.index == 7 ? 1 : data.index == 8 ? 2 : data.index == 9 ? 3 : data.index
                    console.log('tabType', tabType)
                })
                form.on('submit(save)', function () {

                    var dataList = table.getData("serialSlaveDetail3");
                    if (options.ApplicationLayerProtocol == "3") {
                        //mqtts 
                        dataList = table.getData("optionsMqtts");
                    } else if (options.ApplicationLayerProtocol == "4") {
                        dataList = table.getData("optionsMqttsOneNet");
                    } else if (options.ApplicationLayerProtocol == "5") {
                        data1 = table.getData("Modbus1")
                        data2 = table.getData("Modbus2")
                        data3 = table.getData("Modbus3")
                        data4 = table.getData("Modbus4")
                        dataList = data1.concat(data2, data3, data4);
                    } else if (options.ApplicationLayerProtocol == "6") {
                        data1 = table.getData("ConcentratorType1")
                        data2 = table.getData("ConcentratorType2")
                        data3 = table.getData("ConcentratorType3")
                        dataList = data1.concat(data2, data3);
                    }
                    console.log("dataList", dataList)
                    var error = ""
                    dataList.forEach(function (item) {
                        if (options.ApplicationLayerProtocol == "3") {
                            item.MeterAddress = 0;
                            if (item.STCD === "" || item.STCD === undefined) {
                                error = "测站编码不能为空"
                            }
                            if (item.MPCD === "" || item.MPCD === undefined) {
                                error = "测点编码不能为空"
                            }
                        } else if (options.ApplicationLayerProtocol == "4") {
                            item.MeterAddress = 0;
                            if (item.MqttKey === "" || item.MqttKey === undefined) {
                                error = "上传标识不能为空"
                            }
                            if ($("#MqttDataType" + item.ID).val() === "" || $("#MqttDataType" + item.ID).val() === undefined) {
                                error = "数据类型不能为空"
                            } else {
                                item.MqttDataType = parseInt($("#MqttDataType" + item.ID).val())
                            }
                            if (item.MqttStep === "" || item.MqttStep === undefined) {
                                error = "小数点位数不能为空"

                            } else {
                                item.MqttStep = parseInt(item.MqttStep)
                            }
                            if (item.Serial_ID < 0) {
                                //时间戳的格式
                                if (item.MqttDataType != 5) {
                                    error = "时间戳必须选择date数据类型"
                                }
                            }
                            if (item.MqttDataType == 5) {
                                if (item.Serial_ID > 0) {
                                    error = "date数据类型必须选择时间戳参数"
                                }
                            }
                        } else if (options.ApplicationLayerProtocol == "5") {
                            if (item.ModbusTCPType === "" || item.ModbusTCPType === null || item.ModbusTCPType === undefined) {
                                error = "功能码" + item.ModbusTCPType + ",ID:" + item.ID + "功能码错误"

                            }
                            else if (item.ModbusTCPSlaveID === "" || item.ModbusTCPSlaveID === null || item.ModbusTCPSlaveID === undefined) {
                                error = "功能码" + item.ModbusTCPType + ",ID:" + item.ID + "设备地址必填"

                            }
                            else if (item.ModbusTCPAddressID === "" || item.ModbusTCPAddressID === null || item.ModbusTCPAddressID === undefined) {
                                error = "功能码" + item.ModbusTCPType + ",ID:" + item.ID + "寄存器地址必填"

                            }
                            item.MeterAddress = 0;
                            item.ModbusTCPType = parseInt(item.ModbusTCPType);
                            item.ModbusTCPAddressID = parseInt(item.ModbusTCPAddressID);

                        }
                        else if (options.ApplicationLayerProtocol == "6") {
                            item.MeterAddress = 0;

                            // if (item.ConcentratorKey === "" || item.ConcentratorKey === undefined) {
                            //     error = "数据标识不能为空"
                            // }
                            if ($("#ConcentratorKey" + item.ID).val() === "" || $("#ConcentratorKey" + item.ID).val() === undefined) {
                                error = "数据标识不能为空"
                            } else {
                                item.ConcentratorKey = $("#ConcentratorKey" + item.ID).val()
                            }
                            item.ConcentratorType = parseInt(item.ConcentratorType);
                        }
                        else {
                            item.MeterAddress = parseInt(item.MeterAddress);
                        }
                        item.DeviceInfo_Concentrator_ID = parseInt(options.DeviceInfo_Concentrator_ID);
                        item.DeviceInfo_Concentrator_User_ID = parseInt(options.DeviceInfo_Concentrator_User_ID);
                        item.Serial_Slave_Detail_ID = parseInt(item.Serial_Slave_Detail_ID);
                        item.ID = item.ID < 0 ? 0 : item.ID

                    });
                    if (error != "") {
                        layer.msg("保存失败," + error, { icon: 2 });
                        return false
                    }
                    var postData = { DeviceInfo_Detail: dataList };
                    if (dataList.length == 0) {
                        layer.msg("没有数据", {
                            icon: 2
                        });
                        return
                    }
                    //修改上报配置（详情）
                    var loadingIndex = layer.load(3, {
                        content: '保存中...', // 自定义加载文本
                        shade: [0.4, '#fff'], // 遮罩透明度
                        time: 5 * 1000,
                    });
                    EditDeviceInfoDetail(postData).then(function (responseData1) {
                        if (responseData1.success) {
                            GetDeviceInfo().then(function (responseData) {
                                data = responseData;
                                var dataList = [];
                                if (options.ApplicationLayerProtocol != "5" && options.ApplicationLayerProtocol != "6") {
                                    processData(data, -1, dataList);
                                    dataList3.splice(0, dataList3.length, ...dataList);
                                    if (options.ApplicationLayerProtocol == "1") {
                                        table.reload("serialSlaveDetail3", options3, true);
                                    }
                                    if (options.ApplicationLayerProtocol == "3") {
                                        table.reload("optionsMqtts", optionsMqtts, true);
                                    }
                                    if (options.ApplicationLayerProtocol == "4") {
                                        table.reload("optionsMqttsOneNet", optionsMqttsOneNet, true);
                                    }
                                }
                                else if (options.ApplicationLayerProtocol == "5") {
                                    if (tabType == 3) {
                                        processData(data, 1, dataList);
                                        modbusdata1.splice(0, modbusdata1.length, ...dataList);
                                        table.reload("Modbus1", optionsmodbus1, true);
                                    } else if (tabType == 4) {
                                        processData(data, 2, dataList);
                                        modbusdata2.splice(0, modbusdata2.length, ...dataList);
                                        table.reload("Modbus2", optionsmodbus2, true);
                                    } else if (tabType == 5) {
                                        processData(data, 3, dataList);
                                        modbusdata3.splice(0, modbusdata3.length, ...dataList);
                                        table.reload("Modbus3", optionsmodbus3, true);
                                    } else if (tabType == 6) {
                                        processData(data, 4, dataList);
                                        modbusdata4.splice(0, modbusdata4.length, ...dataList);
                                        table.reload("Modbus4", optionsmodbus4, true);
                                    }
                                }
                                else if (options.ApplicationLayerProtocol == "6") {
                                    if (concentratorType == 1) {
                                        processData(data, 1, dataList);
                                        Concentratordata1.splice(0, Concentratordata1.length, ...dataList);
                                        table.reload("ConcentratorType1", optionsConcentratorType1, true);
                                    } else if (concentratorType == 2) {
                                        processData(data, 2, dataList);
                                        Concentratordata2.splice(0, Concentratordata2.length, ...dataList);
                                        table.reload("ConcentratorType2", optionsConcentratorType2, true);
                                    } else if (concentratorType == 3) {
                                        processData(data, 3, dataList);
                                        Concentratordata3.splice(0, Concentratordata3.length, ...dataList);
                                        table.reload("ConcentratorType3", optionsConcentratorType3, true);
                                    }
                                }
                                //form1()
                            });
                        }
                        layer.close(loadingIndex);
                    });
                })
                tableConfigs.forEach(function (config) {
                    var elem = config.elem;
                    var configoptions = config.options;
                    var configdataList = config.dataList;
                    var configdtype = config.type;
                    //console.log("configdtype", configdtype)
                    table.render(configoptions);

                    table.on('tool(' + elem.substring(1) + ')', function (obj) {
                        var dataobj = obj.data; // 获得当前行数据
                        //console.log("dataobj", dataobj)
                        var dataCopy = {
                            Name: dataobj.Name,
                            Device_ID: parseInt(dataobj.Device_ID),
                            MeterAddress: parseInt(dataobj.MeterAddress),
                            ID: dataobj.ID,
                            Serial_Slave_Detail_ID: parseInt(dataobj.Serial_Slave_Detail_ID),
                            Serial_ID: parseInt(dataobj.Serial_ID),
                            Serial_Slave_ID: parseInt(dataobj.Serial_Slave_ID)
                        }
                        if (obj.event === 'detailSave') {
                            // // 保存操作
                            // var postData = { DeviceInfo_Detail: dataCopy };
                            // //修改上报配置（详情）
                            // EditDeviceInfoDetail(postData).then(function (responseData1) {
                            //     GetDeviceInfo().then(function (responseData) {
                            //         data = responseData;
                            //         var dataList = [];
                            //         processData(data, configdtype, dataList);
                            //         configdataList.splice(0, configdataList.length, ...dataList);
                            //         table.reload(elem.substring(1), configoptions, true);
                            //     });
                            // });
                        } else if (obj.event === 'delete') {
                            // 删除操作
                            const postData = { DeviceInfoDetailID: dataobj.ID };
                            console.log("configdataList", configdataList)
                            console.log("dataobj", dataobj)
                            if (dataobj.ID <= 0) {
                                //如果删除的是新增的空行
                                obj.del();
                                configdataList.forEach((item, index) => {
                                    if (item.ID == dataobj.ID) {
                                        configdataList.splice(index, 1);
                                    }
                                });
                                // configdataList.pop() //删除最后一个空元素
                            }
                            else {
                                DeleteDeviceInfoDetail(postData).then(function (deleteresponseData) {
                                    if (deleteresponseData.code == 0) {
                                        GetDeviceInfo().then(function (responseData) {
                                            data = responseData;
                                            var dataList = [];
                                            processData(data, configdtype, dataList);
                                            configdataList.splice(0, configdataList.length, ...dataList);
                                            table.reload(elem.substring(1), configoptions, true);
                                        });
                                    }
                                })
                            }
                        }
                    });

                    table.on('toolbar(' + elem.substring(1) + ')', function (obj) {
                        switch (obj.event) {
                            case 'add':
                                // console.log("dataList3",dataList3)
                                var isAdd = true
                                var meterAddressInit = 2 //初始地址位
                                configdataList.forEach(element => {
                                    // console.log('element', element)
                                    if (element.ID == 0) {
                                        isAdd = false
                                        return
                                    }
                                    if (parseInt(element.MeterAddress) > parseInt(meterAddressInit)) {
                                        meterAddressInit = parseInt(element.MeterAddress)
                                    }
                                });
                                if (configdataList.length > 0 || meterAddressInit != '2') {
                                    meterAddressInit = (parseInt(meterAddressInit) + 1)
                                    meterAddressInits = meterAddressInit
                                }
                                //console.log("meterAddressInit", meterAddressInit)
                                // if (isAdd) {
                                // var dataCopy = {
                                //     Name: '',
                                //     Device_ID: options.id,
                                //     MeterAddress: meterAddressInit,
                                //     ID: 0,
                                //     Serial_Slave_Detail_ID: 0,
                                //     CollectName: '点击新增'
                                // };

                                // configdataList.push(dataCopy);
                                // table.reload(elem.substring(1), configoptions, true);

                                select(0, tree, responseDatas, tableConfigs, dataList3, table)
                                tree.reload('treeSelect', {}); // 重载实例
                                break;
                            //}
                            // else {
                            // layer.msg("有未保存的新增数据", {
                            //     icon: 2
                            // });
                            //break;
                            // }
                            default: {
                                break;
                            }
                        };
                    })
                    table.on('edit(' + elem.substring(1) + ')', function (obj) {
                        // table.on('edit(serialSlaveDetail3)', function (obj) {
                        var field = obj.field; // 得到修改的字段
                        var value = obj.value // 得到修改后的值
                        var oldValue = obj.oldValue // 得到修改前的值 -- v2.8.0 新增
                        var data = obj.data // 得到所在行所有键值
                        var col = obj.getCol(); // 得到当前列的表头配置属性 -- v2.8.0 新增
                        // 值的校验
                        // console.log("field", field)
                        // console.log("value", value)
                        if (field != 'Name' && value.replace(/\s/g, '') === '') {
                            layer.tips('值不能为空', this, { tips: 1 });
                            return obj.reedit(); // 重新编辑 -- v2.8.0 新增
                        } else if (field == "MeterAddress") {
                            var tegexPort = /^[0-9]\d*$/
                            if (!(tegexPort.test(value))) {
                                layer.tips('只能填写正整数', this, { tips: 1 });
                                return obj.reedit();
                            }
                            else if (value > 146) {
                                layer.tips('点号最大为146', this, { tips: 1 });
                                return obj.reedit();
                            }
                            else if (value <= 1) {
                                layer.tips('点号最小为2', this, { tips: 1 });
                                return obj.reedit();
                            }
                        }
                    });
                });

            }
            function select(id, tree, responseDatas, tableConfigs, dataList3, table) {
                console.log("optionsSet", optionsSet)
                layer.open({
                    title: '选择采集点',
                    type: 1,
                    area: ['50%', '80%'],
                    content: `
                    <div class="layui-row" style="padding:10px">  
                        <div class="layui-col-md3 layui-col-md-offset5">
                            <button type="button" class="layui-btn layui-btn-sm" lay-on="getChecked">获取选中节点数据</button>
                        </div>                         
                    </div>
                    <div class="layui-row" style="padding:10px">  
                        <div class="layui-col-md3 layui-col-md-offset5">
                            <a id="treeShow2"></a>
                        </div>                         
                    </div>    
                    <div class="layui-row ${optionsSet.ApplicationLayerProtocol === "4" ? "layui-show" : "layui-hide"}" style="padding:10px">
                        <div class="layui-btn-group layui-col-md-offset4">
                            <button type="button" class="layui-btn layui-btn-primary layui-border-green" lay-on="getTime1">时间戳.秒</button>
                            <button type="button" class="layui-btn layui-btn-primary layui-border-green" lay-on="getTime2">时间戳.毫秒</button>                           
                        </div>                  
                    </div>            
                         `,
                    // cancel: function (index, layero, that) {
                    //     if (id == 0) {
                    //         //新增关闭删除行
                    //         tableConfigs[0].dataList.pop() //删除最后一个空元素
                    //         table.reload(tableConfigs[0].elem.substring(1), tableConfigs[0].options, true);
                    //     }
                    // }
                });
                tree.render({
                    elem: '#treeShow2',
                    data: responseDatas,
                    showCheckbox: true,
                    id: 'treeSelect',
                    // accordion: true ,
                    // onlyIconControl: true,  // 是否仅允许节点左侧图标控制展开收缩
                    click: function (obj) {
                        // if (obj.data.children == null && obj.data.type != "-1") {
                        //     console.log("有效点击", obj.data)
                        //     dataList3.forEach(function (item) {
                        //         if (item.ID == id) {
                        //             item.CollectName = obj.data.title
                        //             item.Serial_Slave_Detail_ID = obj.data.id
                        //             item.Serial_ID = obj.data.serialID
                        //             item.Serial_Slave_ID = obj.data.serialSlaveID
                        //         }
                        //     })
                        //     table.reload(tableConfigs[0].elem.substring(1), tableConfigs[0].options, true);
                        //     layer.closeAll()
                        // }
                        //  else {
                        //     layer.msg("请点击功能码下的数据");
                        // }
                        // layer.msg(JSON.stringify(obj.data));
                        // layer.msg('状态：' + obj.state + '<br>节点数据：' + JSON.stringify(data));
                    }
                })
            }
            function selectEdit(id, tree, responseDatas, tableConfigs, dataList3, table) {
                console.log("dataList3", dataList3)
                layer.open({
                    title: '选择采集点',
                    type: 1,
                    area: ['50%', '80%'],
                    content: `
                    <div class="layui-row">   
                        <div class="layui-col-md3 layui-col-md-offset5">
                            <a id="treeShowEdit"></a> 
                         </div> 
                    </div>
                    <div class="layui-row ${optionsSet.ApplicationLayerProtocol === "4" ? "layui-show" : "layui-hide"}" style="padding:10px">
                        <div class="layui-btn-group layui-col-md-offset4">
                            <button type="button" class="layui-btn layui-btn-primary layui-border-green " lay-on="getTime11">时间戳.秒</button>
                            <button type="button" class="layui-btn layui-btn-primary layui-border-green" lay-on="getTime22">时间戳.毫秒</button>                           
                        </div>                  
                    </div>    
                    `,
                });
                var util = layui.util;
                util.on('lay-on', {
                    getTime11: function () {
                        // var layData = layui.$(this).attr('lay-data');
                        console.log('id:', id);

                        dataList3.forEach(function (item) {
                            if (item.ID == id) {
                                item.CollectName = '时间戳.秒'
                                item.Serial_Slave_Detail_ID = -1
                                item.Serial_ID = -1
                                item.Serial_Slave_ID = -1
                            }
                        })
                        table.reload(tableConfigs.elem.substring(1), tableConfigs.options, true);
                        layer.closeAll()
                    },
                    getTime22: function (ohtis) {
                        dataList3.forEach(function (item) {
                            if (item.ID == id) {
                                item.CollectName = '时间戳.毫秒'
                                item.Serial_Slave_Detail_ID = -2
                                item.Serial_ID = -2
                                item.Serial_Slave_ID = -2
                            }
                        })
                        table.reload(tableConfigs.elem.substring(1), tableConfigs.options, true);
                        layer.closeAll()
                    },
                });
                tree.render({
                    elem: '#treeShowEdit',
                    data: responseDatas,
                    click: function (obj) {
                        if (obj.data.children == null && obj.data.type != "-1") {
                            dataList3.forEach(function (item) {
                                if (item.ID == id) {
                                    item.CollectName = obj.data.title
                                    item.Serial_Slave_Detail_ID = obj.data.id
                                    item.Serial_ID = obj.data.serialID
                                    item.Serial_Slave_ID = obj.data.serialSlaveID
                                }
                            })
                            table.reload(tableConfigs.elem.substring(1), tableConfigs.options, true);
                            layer.closeAll()
                        }
                    }
                })
            }
            //获取最后一层的数据
            function findSerialSlaveIDNotZero(data) {
                // 创建一个用于存储结果的数组
                const result = [];

                // 递归函数，用于遍历数据
                function processChildren(children) {
                    for (const item of children) {
                        if (item.children && item.children.length > 0) {
                            // 如果有子节点，递归处理子节点
                            processChildren(item.children);
                        } else {
                            // 如果没有子节点，检查 serialSlaveID 是否不等于 0
                            if (item.serialSlaveID !== 0) {
                                result.push(item);
                            }
                        }
                    }
                }

                // 开始处理数据
                processChildren(data);

                return result;
            }

            //选择不同协议
            function ChangeSelectDisabled(b) {
                if (b) { //选中tcp时
                    $('#TransportLayerProtocol .layui-input.layui-unselect').attr("disabled", true)
                    $('#IP').attr("disabled", true)
                    $('#PORT').attr("disabled", true)
                    $('#DeviceInfoID').attr("disabled", true)

                } else {
                    $('#TransportLayerProtocol .layui-input.layui-unselect').removeAttr("disabled")
                    $('#IP').removeAttr("disabled")
                    $('#PORT').removeAttr("disabled")
                    $('#DeviceInfoID').removeAttr("disabled")
                }
            }
        })
    </script>

</body>

</html>